Skip to content

fix(content): import zod-to-json-schema only for zod v3 schemas - #3826

Open
lazerg wants to merge 2 commits into
nuxt:mainfrom
lazerg:fix/issue-3825-lazy-zod-to-json-schema
Open

fix(content): import zod-to-json-schema only for zod v3 schemas#3826
lazerg wants to merge 2 commits into
nuxt:mainfrom
lazerg:fix/issue-3825-lazy-zod-to-json-schema

Conversation

@lazerg

@lazerg lazerg commented Aug 6, 2026

Copy link
Copy Markdown

🔗 Linked issue

Closes #3825

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

initiateValidatorsContext() imports the zod3 validator dynamically, behind an isPackageInstalled('zod') check, but src/utils/index.ts re-exports z from that same module. The static re-export wins, so dist/module.mjs ends up with a top-level import { zodToJsonSchema, ignoreOverride } from 'zod-to-json-schema' and the module cannot load at all unless that package resolves, even for apps whose collections are all zod v4 and go through the native toJSONSchema() path.

The legacy z export and its .editor() prototype patch move to schema/zod3-legacy.ts, which leaves schema/zod3.ts as a converter-only module like zod4.ts and valibot.ts. It stays out of the eager graph and is loaded only when both zod and zod-to-json-schema are present, so a missing converter now surfaces as the existing "install zod and zod-to-json-schema" error instead of a module resolution crash.

This only covers the first suggestion in the issue. Widening the zod range and moving zod/zod-to-json-schema to optional peer dependencies changes the dependency contract, so I left it out; zod itself is still imported eagerly for the legacy z export.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

@lazerg is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds a Zod 3 legacy compatibility module with editor metadata and a chainable editor method. The public z export now uses this module. The main Zod 3 schema module uses type-only imports and no longer augments Zod prototypes. The validators context checks for zod-to-json-schema before registering the Zod 3 integration. A regression test verifies lazy loading.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #3825 by keeping zod-to-json-schema out of the eager graph and preserving the Zod v4 native conversion path.
Out of Scope Changes check ✅ Passed The changes and regression test directly support the linked issue and contain no unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly identifies the main fix: limiting zod-to-json-schema imports to Zod v3 schemas.
Description check ✅ Passed The description directly explains the module-loading bug, the lazy import fix, and the related compatibility changes.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/content@3826

commit: 5a82f75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefer zod v4's native toJSONSchema() — make the zod-to-json-schema import lazy so v4 consumers don't need it

1 participant